/* $Id: FTGlyph.java 33 2006-09-26 19:35:03Z funsheep $ */
package net.sourceforge.ftgl.glyph;

import java.awt.Shape;
import java.awt.font.ShapeGraphicAttribute;

import net.java.games.jogl.GL;
import net.java.games.jogl.GLU;
import net.sourceforge.ftgl.glfont.FTGlyphContainer;
import net.sourceforge.ftgl.math.FTBBox;

/**
 * FTGlyph is the base class for FTGL glyphs. It provides the interface between Freetype glyphs and
 * their openGL renderable counterparts. This is an abstract class and derived classes must
 * implement the <code>render</code> function.
 * 
 * @see FTGlyphContainer
 * @see FTBBox
 */
public abstract class FTGlyph
{


	protected FTBBox bBox;
	protected Shape glyph;

	/** the glcontext to render with. */
	protected GL gl;
	/** the glucontext to render with. */
	protected GLU glu;


	/**
	 * Constructor
	 * @param glyph The Shape to put in the FTGlyph.
	 */
	public FTGlyph(Shape glyph)
	{
		this.bBox = new FTBBox(glyph);
		this.glyph = glyph;
		//several options:
//		/** due to {@link ShapeGraphicAttribute#getAdvance()} description */
//		this.advance = Math.abs(this.bBox.upperX - this.bBox.lowerX);
//		/** due to {@link ShapeGraphicAttribute} */
//		float shapeadvance = new ShapeGraphicAttribute(glyph, ShapeGraphicAttribute.CENTER_BASELINE, ShapeGraphicAttribute.STROKE).getAdvance();
//		/** or create a {@link java.awt.font.TextLayout} and get the advance for the letter, the shape represents */
//		System.out.println("[Boxed] " + this.advance + " [ShapeAttribute] " + shapeadvance);
//		this.advance = shapeadvance;
	}


	/**
	 * Destructor.
	 */
	public void dispose()
	{
		this.gl = null;
		this.glu = null;
	}

	/**
	 * Sets the gl context for this FTGlyph.
	 * @param gl The new gl context.
	 * @param glu The new glu context.
	 */
	public void setGLGLU(GL gl, GLU glu)
	{
		assert gl != null && glu != null : "GL and GLU shouldnt be null";
		this.gl  = gl;
		this.glu = glu;
	}


	/**
	 * Renders this glyph, translated by the given offset.
	 * @param x The offset's x component.
	 * @param y The offset's y component.
	 * @param z The offset's z z component.
	 */
	public abstract void render(final float x, final float y, final float z);


	/**
	 * Return the bounding box for this glyph.
	 * @return bounding box.
	 */
	public final FTBBox getBBox()
	{
		return this.bBox;
	}

}